package com.gavindon.android.viewmodel

import androidx.lifecycle.viewModelScope
import com.gavindon.android.base.BaseViewModel
import com.gavindon.android.entity.CourseDetailResp
import com.gavindon.android.entity.VideoDetail
import com.gavindon.android.entity.VideoTreeResp
import com.gavindon.android.network.DataResult
import com.gavindon.android.repo.VideoRepo
import kotlinx.coroutines.launch

/**
 * description:
 * Created by liNan on  2022-2-5 13:53
 */
class VideoViewModel : BaseViewModel() {

    private val videoRepo = VideoRepo()

    private val courseTreeLiveData: SingleLiveEvent<DataResult<List<VideoTreeResp>>> =
        SingleLiveEvent()

    private val courseDetailLiveData: SingleLiveEvent<DataResult<VideoDetail>> =
        SingleLiveEvent()

    private val courseDetail2LiveData: SingleLiveEvent<DataResult<CourseDetailResp>> =
        SingleLiveEvent()
    private val courseLstLiveData: SingleLiveEvent<DataResult<List<VideoTreeResp>>> =
        SingleLiveEvent()

    /*获取课时目录 章节*/
    fun getCourseTree(cid: String): SingleLiveEvent<DataResult<List<VideoTreeResp>>> {
        viewModelScope.launch {
            val result = videoRepo.getLessonId(cid)
            courseTreeLiveData.postValue(result)
        }
        return courseTreeLiveData
    }

    fun getLessonDetail(id: String): SingleLiveEvent<DataResult<VideoDetail>> {
        viewModelScope.launch {
            val result = videoRepo.getLessonDetail(id)
            courseDetailLiveData.value = result
        }
        return courseDetailLiveData
    }

    fun getCourseDetail(id: String): SingleLiveEvent<DataResult<CourseDetailResp>> {
        viewModelScope.launch {
            val result = videoRepo.getCourseDetail(id)
            courseDetail2LiveData.postValue(result)
        }
        return courseDetail2LiveData
    }

    /*   *//*获取课程目录*//*
    fun getCourseLst(id: String): SingleLiveEvent<DataResult<List<VideoTreeResp>>> {
        viewModelScope.launch {
            val result = videoRepo.getCourseLst(id)
            courseLstLiveData.postValue(result)
        }
        return courseLstLiveData
    }*/
}